﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace pufflesweb
{
    public partial class register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PModel.User myuser = new PModel.User();
            if (username.Text.Trim() == "" || password.Text.Trim() == "")
            {
                MessageBox.Show("请输入用户名和密码", "提示");
            }
            else if (password.Text.Trim() != repassword.Text.Trim())
            {
                MessageBox.Show("两次密码不一致", "提示");
            }
            else
            {
                if (PBLL.User.Search(this.username.Text) == false)
                {
                    MessageBox.Show("用户名已存在", "提示");
                }
                else
                {
                    myuser.Upassword = int.Parse(this.password.Text);
                    myuser.Username = this.username.Text;
                    myuser.Usex = int.Parse(this.sex.Text);
                    //Response.Redirect("index.aspx");
                    if (PBLL.User.add(myuser))
                    {
                        PModel.User user = PBLL.User.Getuser(myuser.Username);
                        PF.SessionHelper.SetSession("user", user);
                        PF.JsHelper.AlertAndParentUrl("注册成功", "index.aspx");
                    }
                    else
                    {
                        PF.JsHelper.AlertAndParentUrl("注册失败,用户名重复，请重新输入", "add.aspx");
                    }
                }
                
            }
        }
    }
}